package com.iqiao.platform.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iqiao.common.web.Constant;
import com.iqiao.platform.dao.RoleDao;
import com.iqiao.platform.model.Role;
import com.iqiao.platform.service.RoleService;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDao roleDao;

    @Override
    @Transactional(readOnly = true)
    public PageInfo<Role> findPage(Map<String, Object> params) {
        int pageNo = MapUtils.getIntValue(params, "pageNo", Constant.PAGE_NO);
        int pageSize = MapUtils.getIntValue(params, "pageSize", Constant.PAGE_SIZE);
        return this.findPage(pageNo, pageSize, params);
    }

    @Override
    @Transactional(readOnly = true)
    public PageInfo<Role> findPage(int pageNo, int pageSize, Map<String, Object> params) {
        PageHelper.startPage(pageNo, pageSize);
        List<Role> roleList = roleDao.findAll(params);
        return new PageInfo<Role>(roleList);
    }

    @Override
    @Transactional(readOnly = true)
    public Role findById(Long roleId) {
        return null;
    }
}
